home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / TASEXAM6.ARJ / PEAKS.TAS < prev    next >
Text File  |  1991-09-24  |  9KB  |  230 lines

  1. {
  2.       * CAUTION YOU MUST HAVE THE SP-500 IN YOUR DATABASE FOR THE
  3.         INDEX TO WORK.  ALSO YOU MAY NEED TO INCREASE YOUR SYMBOL
  4.         SIZE IN THE CONFIGURE SCREEN OF TAS.*
  5.       This script tries to determine cycle length by looking at the
  6.       average peaks and troughs of a zigzag indicator.  The last five
  7.       peaks and troughs are averaged to try to determine the next
  8.       peak and trough.  A second function of this script is to determine
  9.       trend strength by looking at a cycle average of price and volume.
  10.       The stocks are also compared to the SP-500 and then a percent
  11.       number is given to how over bought or over sold they are.
  12.       All indicators are based on the time period found in the zigzag
  13.       function.  Cycle studies are usually given a 15% bandwidth so
  14.       keep this in mind. Also this looks at short cycles which may
  15.       be under the influence of longer cycles.
  16.       May 1991. Jerry Green
  17. }
  18. #max_quotes 120
  19. #index 'SP-500'
  20. #output_file 'Peaks.LST'
  21. rs_trgr : number;                { define some numbers }
  22. so_trgr : number;
  23. rt_trgr : number;
  24. days_back : number;
  25. rs_c : array;                     { define some arrays }
  26. so_c : array;
  27. rt_c : array;
  28. rs_sort : array;
  29. Z : ARRAY;
  30. if first_ticker then
  31. begin
  32. writeln(' CYCLE, TREND AND VALUE STUDY BASED ON AVERAGE ZIGZAG CYCLES');
  33. writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
  34. writeln(' ');
  35. toda = date;        { get last day in first ticker}
  36. end;
  37. if quote_count <= 100 OR date <> toda then
  38. goto skipticker;             {skip short data file}
  39. begin
  40. pk_5 = 0;                    {make sure we are clear from}
  41. tr_5 = 0;                    {one ticker to the next}
  42. pk_4 = 0;                    {varibles to store peak and }
  43. tr_4 = 0;                    {trough differences }
  44. pk_3 = 0;
  45. tr_3 = 0;
  46. pk_2 = 0;
  47. tr_2 = 0;
  48. pk_1 = 0;
  49. tr_1 = 0;
  50. pks_t = 0;                   {peaks to troughs}
  51. trs_p = 0;                   {troughs to peaks}
  52. pks_ta = 0;                  {average of pks_t}
  53. trs_pa = 0;                  {average of trs_p}
  54. nx_pk = 0;                   {next peak}
  55. nx_tr = 0;                   {next trough}
  56. s_t = 0;                     {rate of change for ticker}
  57. s_p = 0;                     {rate of change for index}
  58. rel_str = 0;                 {relative strength to index}
  59. ob_os = 0;                   {overbought oversold}
  60. rs_trgr = 0;                 {relative strength accumulator}
  61. so_trgr = 0;                 {stochastic accumulator}
  62. rt_trgr = 0;                 {rate of change accumulator}
  63. rs_sort = 0;                 {total of trgrs}
  64. pt1 = 0;                     {varibles for storing peaks}
  65. pt2 = 0;
  66. pt3 = 0;
  67. pt4 = 0;
  68. pt5 = 0;
  69. tp1 = 0;                     {varibles for storing troughs}
  70. tp2 = 0;
  71. tp3 = 0;
  72. tp4 = 0;
  73. tp5 = 0;
  74. {-------------------ZIGZAG STUDY STARTS HERE-------------------}
  75. if C >= 100  then             {check close to determine %}
  76.      z_v = 2;                 {calculate a zigag ind }
  77. if C <= 100 then
  78.      z_v = 5;
  79. Z = ZIG(c,z_v,'%');
  80. pt5 = peak(Z,5);              {get peaks back 5 waves}
  81. pt4 = peak(Z,4);
  82. pt3 = peak(Z,3);
  83. pt2 = peak(Z,2);
  84. pt1 = peak(Z,1);
  85. tp5 = trough(Z,5);            {get troughs back 5 waves}
  86. tp4 = trough(Z,4);
  87. tp3 = trough(Z,3);
  88. tp2 = trough(Z,2);
  89. tp1 = trough(Z,1);
  90. if pt1 >= 0 then          {don't let a peak = 0}
  91.   pt1 = pt2;
  92. if tp1 >= 0 then          {don't let a trough = 0}
  93.   tp1 = tp2;
  94. if pt5 < tp5 then         {check out the waves dude}
  95. goto backpeak             {make sure you catch the first one}
  96. else
  97. goto backtrough;
  98. :backpeak
  99. pk_5 = pt5 - tp5;
  100. tr_5 = tp5 - pt4;         {now the cycle analysis starts}
  101. pk_4 = pt4 - tp4;         {we are finding the days from }
  102. tr_4 = tp4 - pt3;         {peak to trough, trough to peak}
  103. pk_3 = pt3 - tp3;         {the zigzag is used because it}
  104. tr_3 = tp3 - pt2;         {gives the best veiw of the past}
  105. pk_2 = pt2 - tp2;         {by looking ahead in the data }
  106. tr_2 = tp2 - pt1;         {this can tell us the cycles }
  107. pk_1 = pt1 - tp1;
  108. tr_1 = tp1;
  109. goto cycle;
  110. :backtrough
  111. tr_5 = tp5 - pt5;         {two models are used to take}
  112. pk_5 = pt5 - tp4;         {into account the difference }
  113. tr_4 = tp4 - pt4;         {in first peak or first trough}
  114. pk_4 = pt4 - tp3;
  115. tr_3 = tp3 - pt3;
  116. pk_3 = pt3 - tp2;
  117. tr_2 = tp2 - pt2;
  118. pk_2 = pt2 - tp1;
  119. tr_1 = tp1 - pt1;
  120. pk_1 = pt1;
  121. goto cycle;
  122. :cycle
  123. pks_t = pk_5+pk_4+pk_3+pk_2+pk_1;   {add peaks to troughs}
  124. trs_p = tr_5+tr_4+tr_3+tr_2+tr_1;   {add troughs to peaks}
  125. pks_ta = (0-(pks_t/5));             {determine peaks and change to +}
  126. trs_pa = (0-(trs_p/5));             {do same for troughs            }
  127.   nx_tr = pks_ta+pk_1;    {peak and trough functions return negative}
  128.   nx_pk = trs_pa+tr_1;    {numbers so we add last to avg to find next}
  129. avg_c = (pks_ta + trs_pa)/2;     {calculate and average cycle }
  130. days_back = avg_c;               {days to go back in rank section}
  131. avg_c = int(avg_c);
  132. {---------------ZIGZAG STOPS AND OB-OS STARTS------------------}
  133. rs_c = rsi(avg_c);                    { calculate an RSI }
  134. so_c = stoch(int(avg_c/2),3);         { STOCHASTIC }
  135. rt_c = roc(c,avg_c,'%');              { RATE OF CHANGE }
  136. bb_top = bbandt(avg_c,2);             { BOLLENGER TOP BAND }
  137. bb_bot = bbandb(avg_c,2);             { BOLLINGER BOTTOM BAND }
  138. :loop1
  139. if rs_c[days_back] > 70 then       { a loop to accumulate counts for }
  140.       rs_trgr = rs_trgr + 1;       { indicator performance }
  141. if rs_c[days_back] < 30 then
  142.       rs_trgr = rs_trgr - 1;
  143. if so_c[days_back] > 80 then
  144.       so_trgr = so_trgr + 1;
  145. if so_c[days_back] < 20 then
  146.       so_trgr = so_trgr - 1;
  147. if c > 100 then
  148.    n = 2 and nn = -2                { if ticker is > 100 change ROC }
  149. else                                { to look at 2% change, if cheaper }
  150.    n = 7 and nn = -7;               { use 7% a number William Oneil likes}
  151. if rt_c[days_back] > n then
  152.       rt_trgr = rt_trgr + 1;
  153. if rt_c[days_back] < nn then
  154.       rt_trgr = rt_trgr - 1;
  155. days_back = days_back + 1;          { increase counter by 1 until today }
  156. if days_back >= 1 then              { is reached. today is 0  }
  157. goto done
  158. else
  159. goto loop1;
  160. :done
  161. rs_sort = rs_trgr + so_trgr + rt_trgr;    { add them for final rank}
  162. {------------OB-OS STOPS AND TREND STUDY STARTS HERE--------}
  163. AVG_VOL = MOV(V,avg_c/2,'E'); {moving average of 1/2 cycle on volume}
  164. IF V < AVG_VOL THEN                       {if todays vol is less than}
  165.      VS_TRGR = - 1;                       {the avgerage VS_TRGR =-1}
  166. ELSE                                      {if greater then VS_TRGR =1}
  167.      VS_TRGR = 1;
  168. AVG_CLSE := MOV(C,avg_c,'E');             {use same logic for CS_TRGR}
  169. IF C < AVG_CLSE THEN
  170.      CS_TRGR = -1;
  171. ELSE
  172.      CS_TRGR = 1;
  173. IF CS_TRGR = 1 AND VS_TRGR = 1 THEN       {this is typical thinking of}
  174. begin                                     {how vol and price interact }
  175.      trend = 'STRONG UP  -> HOLD LONG';    { refer to Jack}
  176.      su_trnd = su_trnd + 1;               {Schwager's book A COMPLETE  }
  177. end;                                      {GUIDE TO THE FUTURES MARKETS}
  178. IF CS_TRGR = 1 AND VS_TRGR = -1 THEN      {pages 367_371.}
  179. begin
  180.      trend = 'WEAK UP  -> SELL ???'; {we also keep track of the}
  181.      wu_trnd = wu_trnd + 1;               {trends for a summary}
  182. end;
  183. IF CS_TRGR = -1 AND VS_TRGR = -1 THEN
  184. begin
  185.      trend = 'STRONG DN  -> HOLD SHORT';
  186.      sd_trnd = sd_trnd + 1;
  187. end;
  188. IF CS_TRGR = -1 AND VS_TRGR = 1 THEN
  189. begin
  190.      trend = 'WEAK DN  -> BUY ???';
  191.      wd_trnd = wd_trnd + 1;
  192. end;
  193. IF AVG_VOL = 0 THEN
  194.      trend = 'TICKER W/NO VOL';
  195. {------------------TREND STUDY STOPS HERE------------}
  196. writeln(ticker,' ','SHORT TERM TIMING AT',' ',avg_c,' ','day cycle',
  197. ' ',z_v,' ','% ZIGZAG');
  198. writeln('           ','Average peak to trough',pks_ta,' ','days');
  199. writeln('           ','Average trough to peak',trs_pa,' ','days');
  200. writeln('           ','Next peak  ',' ',nx_pk,' ','Last peak  ',' ',pt1);
  201. writeln('           ','Next trough',' ',nx_tr,' ','Last trough',' ',tp1);
  202. writeln('           ','Close today','  ','Last peak','  ','Last trough');
  203. writeln('           ',c,'     ',c[pt1],'    ',c[tp1]);
  204. writeln('           ','Possible gain',' ',((c[pt1]-c)/c[pt1]),' ','%');
  205. writeln('           ','Possible risk',' ',((c-c[tp1])/c),' ','%');
  206. writeln('           ','Volume & price trend',' ',trend);
  207. av_cyc = int(0 - avg_c);
  208. s_p = ((index-index[av_cyc])/index[av_cyc])+1;
  209. s_t = ((c-c[av_cyc])/c[av_cyc])+1;
  210. rel_str = 50 + (100*((s_t/s_p)-1));
  211. writeln('           ',avg_c,' ','Day Relative strength',' ',rs_c);
  212. writeln('           ',int(avg_c/2),' ','Day Stochastic',' ',so_c);
  213. writeln('           ',avg_c,' ','Day Rate of Change',' ',rt_c);
  214. writeln('           ',avg_c,' ','Day Top Bollinger Band',' ',bb_top);
  215. writeln('           ',avg_c,' ','Day Bottom Bollinger Band',' ',bb_bot);
  216. writeln('           ','Relative strength to S&P. 50 is even',' ',rel_str);
  217. if rs_sort = 0 then
  218. writeln('           ','Ticker is evenly valued at this cycle!');
  219. if rs_sort <> 0 then
  220. ob_os = (rs_sort/avg_c)*100;
  221. if rs_sort < 0 then
  222. writeln('           ','Ticker is oversold by',' ',ob_os,' ','%');
  223. if rs_sort > 0 then
  224. writeln('           ','Ticker is overbought by',' ',ob_os,' ','%');
  225. writeln('------------------------------------------------------------');
  226. end;
  227. :skipticker
  228. if last_ticker then
  229. end;
  230.